<script type="text/javascript">
	function validateForm()
	{
		var name=document.forms["inputUser"]["name"].value;
		var error = "";
		if (name==null || name=="")
			error += "Please fill the name<br>"; 
		var clas=document.forms["inputUser"]["clas"].value;
		if (clas==null || clas=="")
			error += "Please fill the class<br>"; 
		var id=document.forms["inputUser"]["id"].value;
		if (id==null || id=="")
			error += "Please fill ID"; 
		if (error != "")
		{
			document.getElementById('error').innerHTML=error;
			return false;
		}
		else 
			return true;
	}
        function validateForm2()
	{
            var name=document.getElementById('ename').value;
            var clas=document.getElementById('eclass').value;
            var id=document.getElementById('eid').value;
		var error = "";
		if (name==null || name=="")
			error += "Please fill the name<br>"; 
		if (clas==null || clas=="")
			error += "Please fill the class<br>"; 
		if (id==null || id=="")
			error += "Please fill ID"; 
		if (error != "")
		{
			document.getElementById('error').innerHTML=error;
			document.getElementById('confirmEdit').disabled=true;
		}
		else
                    document.getElementById('error').innerHTML="";
                    document.getElementById('confirmEdit').disabled=false;
	}
	function showTable()
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("showTable").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=showUser",true);
		xmlhttp.send(null);
	}

	function deleteUser(userid)
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("showTable").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=deleteUser&userid="+userid,true);
		xmlhttp.send(null);
	}
        
        function editUser(userid)
	{
		var xmlhttp;
                var name=document.getElementById('ename').value;
                var clas=document.getElementById('eclass').value;
                var id=document.getElementById('eid').value;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("showTable").innerHTML=xmlhttp.responseText;
                                document.getElementById("editPlace").innerHTML="Successfully edited";
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=editUser&userid="+userid+"&name="+name+"&clas="+clas+"&id="+id,true);
		xmlhttp.send(null);
	}
        
        function showEditUser(userid)
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("editPlace").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=showEditUser&userid="+userid,true);
		xmlhttp.send(null);
	}
</script>

<body onload="showTable()">
<form name='inputUser' id ='register' action='Controller.php?action=inputUser' method='post' onsubmit='return validateForm()'>
<fieldset >
<legend>Input broker</legend>
<br> 
<label for='name' >Name*:</label>
 <input type='text' name='name' id='name' maxlength="50" />
 <br>
<label for='class' >Class*:</label>
<input type='text' name='clas' id='clas' maxlength="50" />
<br>
<label for='id' >ID*:</label>
 <input type='text' name='id' id='id' maxlength="50" />
 <br>
<input type="submit" value="Sign up">
<input type='reset' value='Reset'>
</fieldset>
</form>
<h3>Student Information</h3>
<div id='showTable'></div>
<br>
<h3>Edit Place</h3>
<div id='editPlace' onkeyup='validateForm2()'></div>
<br>
<h3>Warning</h3>
<font color='red'><p id='error'></p></font>
</body>